/*
* Accord Software, Inc.
*
* Tutorial 06 - CIDL file.
*
* Print singly linked circular list
*
* 1 --> 2 --> 3 --> 4
* ^ |
* | v
* 8 <-- 7 <-- 6 <-- 5
*
*/
#include "circular.h"
int
addcirc1(count, lp)
int count;
struct list1 *lp;
{
int j;
struct list1 *first;
int sum = 0;
first = lp;
for (j = 0; j < count; j++) {
printf("number = ");
while (lp->next != first) {
printf("%d ", lp->number);
sum += lp->number;
lp = lp->next;
}
sum += lp->number;
printf("%d \n", lp->number);
lp = first;
}
return sum;
}
/*
* Print doubly linked circular list
*
* 1 <---> 2 <---> 3 <---> 4
* ^ ^
* | |
* v v
* 8 <---> 7 <---> 6 <---> 5
*/
int
addcirc2(count, direction, lp)
int count;
int direction;
struct list2 *lp;
{
int j;
struct list2 *first = lp;
int sum = 0;
if (direction == FORWARD)
printf("looping forward\n");
else
printf("looping backward\n");
lp = first;
for (j = 0; j < count; j++) {
printf("number = ");
if (direction == FORWARD)
while (lp->next != first) {
printf("%d ", lp->number);
sum += lp->number;
lp = lp->next;
}
else
while (lp->prev != first) {
printf("%d ", lp->number);
sum += lp->number;
lp = lp->prev;
}
sum += lp->number;
printf("%d\n", lp->number);
lp = first;
}
return sum;
}